# Copyright (2010) Thomas Paviot, tpaviot@gmail.com.
#
# This file is distributed under the terms of the OpenCASCADE Technology Public License 6.3, August 2008
# Complete text of this license can be read online: http://www.opencascade.org/getocc/license/
#

# REQUIREMENTS: this script needs CMake 2.6 or higher. Downloads are available at http://www.cmake.org

# How to build OpenCASCADE using CMake under Unix (Linux, Darwin etc.)?
# 1. Copy this file, as-is, to the OpenCASCADE/ros folder
# 2. Make a build directory somewhere outside the OpenCASCADE source tree
# 3. cmake "relative/path/to/OpenCASCADE/ros"
# 4. make
# 5. make install (or sudo make install)

# How to build OpenCASCADE using CMake under Windows (Linux, Darwin etc.)?
# 1. Copy this file, as-is, to the /ros folder
# 2. Launch the cmake-gui, and select the /ros folder
# 3. You can choose whatever you want as an install directory
# 4. Click 'Configure'
# 5. Choose your generator
# 6. When configure is achived, you can change the variable with a red background
# 7. Click 'Generate'
# 8. From your IDE, open the generated makefile and run the compilation.

# VERSION 0.2
# History
# 0.1 : initial release
# 0.2 : added *.c in source files, scanning ./drv directory, 3 more ToolKits, install
# 0.3a: continuation of 0.2 filling in todos

PROJECT(OpenCASCADE)

SET(OpenCASCADE_VERSION_MAJOR 6)
SET(OpenCASCADE_VERSION_MINOR 3)
SET(OpenCASCADE_VERSION_PATCH 0)

# Set the minimum version of cmake required to 2.6
CMAKE_MINIMUM_REQUIRED( VERSION 2.6 )

IF( "${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" LESS 2.5 )
	MESSAGE( FATAL_ERROR "CMake >= 2.6.0 required" )
ENDIF( "${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" LESS 2.5 )

IF( NOT DEFINED OPENCASCADE_BUILD_TYPE )
	SET( OPENCASCADE_BUILD_TYPE "Release" CACHE STRING "Build type" ) # By default set release build
ENDIF( NOT DEFINED OPENCASCADE_BUILD_TYPE )
SET( CMAKE_BUILD_TYPE ${OPENCASCADE_BUILD_TYPE} CACHE INTERNAL "Build type,
	immutable" FORCE )

IF( NOT DEFINED OPENCASCADE_BUILD_SHARED_LIB )
	SET( OPENCASCADE_BUILD_SHARED_LIB ON )
ENDIF( NOT DEFINED OPENCASCADE_BUILD_SHARED_LIB )
IF( NOT DEFINED OPENCASCADE_MODEL )
	SET( OPENCASCADE_MODEL ON )
ENDIF( NOT DEFINED OPENCASCADE_MODEL )
IF( NOT DEFINED OPENCASCADE_OCAF )
	SET( OPENCASCADE_OCAF ON )
ENDIF( NOT DEFINED OPENCASCADE_OCAF )
IF( NOT DEFINED OPENCASCADE_DATAEXCHANGE )
	SET( OPENCASCADE_DATAEXCHANGE ON )
ENDIF( NOT DEFINED OPENCASCADE_DATAEXCHANGE )
IF( NOT DEFINED OPENCASCADE_DRAW )
	SET( OPENCASCADE_DRAW OFF )
ENDIF( NOT DEFINED OPENCASCADE_DRAW )
IF( NOT DEFINED OPENCASCADE_VISUALISATION )
	SET( OPENCASCADE_VISUALISATION ON )
ENDIF( NOT DEFINED OPENCASCADE_VISUALISATION )
IF( NOT DEFINED OPENCASCADE_WOK )
	SET( OPENCASCADE_WOK OFF )
ENDIF( NOT DEFINED OPENCASCADE_WOK )
IF( NOT DEFINED OPENCASCADE_WRAPPERS )
	SET( OPENCASCADE_WRAPPERS OFF )
ENDIF( NOT DEFINED OPENCASCADE_WRAPPERS )

OPTION( OPENCASCADE_BUILD_SHARED_LIB "Build shared OpenCASCADE libs"
	${OPENCASCADE_BUILD_SHARED_LIB} )
OPTION( OPENCASCADE_MODEL "Build model components" ${OPENCASCADE_MODEL} )
OPTION( OPENCASCADE_OCAF "Build application framework" ${OPENCASCADE_OCAF} )
OPTION( OPENCASCADE_DATAEXCHANGE "Build data exchange"
	${OPENCASCADE_DATAEXCHANGE} )
OPTION( OPENCASCADE_DRAW "Build test harness \(DRAW\)" ${OPENCASCADE_DRAW} )
OPTION( OPENCASCADE_WOK "Build development tools \(WOK\)" ${OPENCASCADE_WOK} )
OPTION( OPENCASCADE_WRAPPERS "Build wrapper libraries" ${OPENCASCADE_WRAPPERS} )
OPTION( OPENCASCADE_VISUALISATION "Build visualisation component"
	${OPENCASCADE_VISUALISATION} )

IF( NOT DEFINED OPENCASCADE_INSTALL_PREFIX )
	IF( WIN32 )
		SET(OPENCASCADE_INSTALL_PREFIX
			"c:/OpenCASCADE-${OpenCASCADE_VERSION_MAJOR}.${OpenCASCADE_VERSION_MINOR}.${OpenCASCADE_VERSION_PATCH}")
	ELSE( WIN32 )
		SET(OPENCASCADE_INSTALL_PREFIX
			"/usr/local")
	ENDIF( WIN32 )
ENDIF( NOT DEFINED OPENCASCADE_INSTALL_PREFIX )

SET( OPENCASCADE_INSTALL_PREFIX ${OPENCASCADE_INSTALL_PREFIX} CACHE
	PATH "Install prefix prepended to target to create install location" )
SET( CMAKE_INSTALL_PREFIX "${OPENCASCADE_INSTALL_PREFIX}" CACHE INTERNAL "Prefix
	prepended to install directories if target destination is not absolute,
	immutable" FORCE )

IF( OPENCASCADE_BUILD_SHARED_LIB )
	SET( OPENCASCADE_LIBRARY_TYPE SHARED )
	SET( OPENCASCADE_INSTALL_TYPE LIBRARY )
	IF( WIN32 )
		SET( OPENCASCADE_INSTALL_TYPE RUNTIME )
	ENDIF( WIN32 )
ELSE( OPENCASCADE_BUILD_SHARED_LIB )
	SET( OPENCASCADE_LIBRARY_TYPE STATIC )
	SET( OPENCASCADE_INSTALL_TYPE ARCHIVE )
	IF ( WIN32 )
		ADD_DEFINITIONS("-DHAVE_NO_DLL")
	ENDIF( WIN32 )
ENDIF( OPENCASCADE_BUILD_SHARED_LIB )

#
# Check components dependencies
#
IF(OPENCASCADE_DRAW AND NOT OPENCASCADE_DATAEXCHANGE)
	SET(OPENCASCADE_DATAEXCHANGE ON CACHE BOOL "Build data exchange")
ENDIF(OPENCASCADE_DRAW AND NOT OPENCASCADE_DATAEXCHANGE)
IF(OPENCASCADE_DATAEXCHANGE AND NOT OPENCASCADE_OCAF)
	SET(OPENCASCADE_OCAF ON CACHE BOOL "Build application framework" FORCE)
ENDIF(OPENCASCADE_DATAEXCHANGE AND NOT OPENCASCADE_OCAF)
IF(OPENCASCADE_OCAF AND NOT OPENCASCADE_VISUALISATION)
	SET(OPENCASCADE_VISUALISATION ON CACHE BOOL 
		"Build visualisation component" FORCE)
ENDIF(OPENCASCADE_OCAF AND NOT OPENCASCADE_VISUALISATION)
IF(OPENCASCADE_VISUALISATION AND NOT OPENCASCADE_MODEL)
	SET(OPENCASCADE_MODEL ON CACHE BOOL "Build model components" FORCE)
ENDIF(OPENCASCADE_VISUALISATION AND NOT OPENCASCADE_MODEL)
IF(OPENCASCADE_DRAW AND NOT OPENCASCADE_VISUALISATION)
SET(OPENCASCADE_VISUALISATION ON CACHE BOOL 
	"Build visualisation component" FORCE)
ENDIF(OPENCASCADE_DRAW AND NOT OPENCASCADE_VISUALISATION)
IF(OPENCASCADE_WOK AND NOT OPENCASCADE_DRAW)
	SET(OPENCASCADE_DRAW ON CACHE BOOL "Build test harness \(DRAW\)" FORCE)
ENDIF(OPENCASCADE_WOK AND NOT OPENCASCADE_DRAW)


SET(FOUNDATION_PKGS TKernel TKMath TKAdvTools)
FILE(GLOB OS_TCL_SCRIPTS src/OS/*.tcl)
SET(UnitsAPI_INSTALL_FILES src/UnitsAPI/Lexi_Expr.dat
	src/UnitsAPI/Units.dat)
SET(OS_INSTALL_FILES ${OS_TCL_SCRIPTS})
SET(FOUNDATION_INSTALL_PKGS UnitsAPI OS)

IF (OPENCASCADE_MODEL)
	SET(MODELLINGDATA_PKGS TKG2d TKG3d TKGeomBase TKBRep)
	SET(MODELLINGALGORITHMS_PKGS TKGeomAlgo TKTopAlgo TKPrim TKBO TKHLR TKMesh
		TKShHealing TKBool TKXMesh TKFillet TKFeat TKOffset)
ENDIF (OPENCASCADE_MODEL)

IF(OPENCASCADE_VISUALISATION)
	FIND_PACKAGE(OpenGL)
	MESSAGE(STATUS "OPENGL LIBS: ${OPENGL_LIBRARIES}")
	MESSAGE(STATUS "THREAD LIB??: ${CMAKE_THREAD_LIBS_INIT}")
	SET(VISUALISATION_PKGS TKService TKV2d TKV3d TKOpenGl TKMeshVS TKNIS)
	FILE(GLOB TEXTURES_RGB_FILES src/Textures/*.rgb)
	SET(Textures_INSTALL_FILES ${TEXTURES_RGB_FILES})
	FILE(GLOB FONTMFT_MFT_FILES src/FontMFT/*.mft)
	SET(FontMFT_INSTALL_FILES ${FONTMFT_MFT_FILES})
	SET(VISUALISATION_INSTALL_PKGS FontMFT Textures)
ENDIF(OPENCASCADE_VISUALISATION)

IF(OPENCASCADE_OCAF)
	SET(OCAF_PKGS TKCDF PTKernel TKLCAF FWOSPlugin TKPShape TKCAF TKBinL
		TKXmlL TKTObj TKShapeSchema TKPLCAF TKBin TKXml TKBinTObj TKXmlTObj
		TKPCAF TKStdLSchema TKStdSchema StdPlugin XmlPlugin BinPlugin
		StdLPlugin BinLPlugin XmlLPlugin BinTObjPlugin XmlTObjPlugin)
	SET(StdResource_INSTALL_FILES src/StdResource/MDTV-Standard.xwd
		src/StdResource/Plugin  src/StdResource/Standard
		src/StdResource/Standard.us  src/StdResource/StandardLite
		src/StdResource/XCAF  src/StdResource/dftree.tcl)
	FILE(GLOB XMLOCAFRESOURCE_XSD_FILES src/XmlOcafResource/*.xsd)
	SET(XmlOcafResource_INSTALL_FILES ${XMLOCAFRESOURCE_XSD_FILES})
	SET(OCAF_INSTALL_PKGS StdResource XmlOcafResource)
ENDIF(OPENCASCADE_OCAF)

IF(OPENCASCADE_DATAEXCHANGE)
	SET(DATAEXCHANGE_PKGS TKVRML TKXCAF TKSTL TKXSBase TKXCAFSchema
		TKXmlXCAF TKBinXCAF TKSTEPBase TKIGES TKSTEPAttr TKSTEP209 TKXDEIGES
		TKSTEP TKXDESTEP XCAFPlugin XmlXCAFPlugin BinXCAFPlugin)
	SET(SHMessage_INSTALL_FILES src/SHMessage/SHAPE.fr src/SHMessage/SHAPE.us)
	SET(XSMessage_INSTALL_FILES src/XSMessage/IGES.fr src/XSMessage/IGES.us
		src/XSMessage/XSTEP.fr src/XSMessage/XSTEP.us)
	SET(XSTEPResource_INSTALL_FILES src/XSTEPResource/IGES  src/XSTEPResource/STEP)
	SET(DATAEXCHANGE_INSTALL_PKGS SHMessage XSMessage XSTEPResource)
ENDIF(OPENCASCADE_DATAEXCHANGE)

IF(OPENCASCADE_DRAW)
	SET(DRAW_PKGS TKDraw TKTopTest TKViewerTest TKXSDRAW TKDCAF TKXDEDRAW
		TKTObjDRAW)
	FILE(GLOB DRAWRESOURCES_TCL_FILES src/DrawResources/*.tcl)
	SET(DrawResources_INSTALL_FILES ${DRAWRESOURCES_TCL_FILES}
		src/DrawResources/DRAW.doc src/DrawResources/DRAW.info
		src/DrawResources/DrawDefault src/DrawResources/DrawPlugin
		src/DrawResources/demo src/DrawResources/demo.bat
		src/DrawResources/idoc src/DrawResources/lamp.ico
		src/DrawResources/mdltest src/DrawResources/mkdoc
		src/DrawResources/tdoc src/DrawResources/test2xl
		src/DrawResources/vmdltest src/DrawResources/wing.brep)
	SET(DRAW_INSTALL_PKGS DrawResources)
	SET(DRAW_APP DRAWEXE)
ENDIF(OPENCASCADE_DRAW)

IF(OPENCASCADE_WOK)
	SET(WOK_PKGS TKWOK TKWOKTcl TKTCPPExt TKCDLFront TKCPPExt TKCPPClient
		TKIDLFront TKCPPJini TKCPPIntExt TKCSFDBSchema WOKSH WOKLibs)
ENDIF(OPENCASCADE_WOK)

IF(OPENCASCADE_WRAPPERS)
	FIND_PACKAGE(JNI)
	#MESSAGE(STATUS "Jni stuff: ${JNI_INCLUDE_DIRS}")
	#MESSAGE(STATUS "Jni stuff: ${JNI_LIBRARIES}")
	SET(WRAPPER_PKGS TKjcas)
ENDIF(OPENCASCADE_WRAPPERS)

SET( CMAKE_DEBUG_POSTFIX "d" )

INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}/inc
	${CMAKE_CURRENT_SOURCE_DIR}/inc ${JNI_INCLUDE_DIRS})

####################################
# Looking for required packages    #
####################################
INCLUDE(FindThreads)
IF(OPENCASCADE_DRAW)
	IF(CMAKE_USE_PTHREADS_INIT)
		SET(THREAD_LIBRARY pthread)
	ENDIF(CMAKE_USE_PTHREADS_INIT)
	#IF(LINUX)
	#	FIND_PACKAGE(X11 REQUIRED)
	#	MESSAGE(STATUS "X11 LIBS: ${X11_LIBRARIES}")
	#ENDIF(LINUX)
	FIND_PACKAGE(TCL REQUIRED)
ENDIF(OPENCASCADE_DRAW)
# TODO: add all required other external packages

###################################################
# Check required headers, functions and libraries #
###################################################
IF (NOT WIN32)
    # Check headers
    # I think these should all be check cxx headers, as I think there is no c
    # compilation anywhere in OpenCASCADE
    INCLUDE(CheckIncludeFile)
    #INCLUDE(CheckIncludeFiles)
    CHECK_INCLUDE_FILE(alloca.h HAVE_ALLOCA_H)
    CHECK_INCLUDE_FILE(dlfcn.h HAVE_DLFCN_H)
    CHECK_INCLUDE_FILE(dl.h HAVE_DL_H)
    CHECK_INCLUDE_FILE(ieeefp.h HAVE_IEEEFP_H)
    CHECK_INCLUDE_FILE(time.h HAVE_TIME_H)
    CHECK_INCLUDE_FILE(sys/time.h HAVE_SYS_TIME_H)
    CHECK_INCLUDE_FILE(pwd.h HAVE_PWD_H)
    CHECK_INCLUDE_FILE(sys/statvfs.h HAVE_SYS_STATVFS_H)
    CHECK_INCLUDE_FILE(sys/vfs.h HAVE_SYS_VFS_H)
    CHECK_INCLUDE_FILE(sys/param.h HAVE_SYS_PARAM_H)
    CHECK_INCLUDE_FILE(osfcn.h HAVE_OSFCN_H)
    CHECK_INCLUDE_FILE(netdb.h HAVE_NETDB_H)
    CHECK_INCLUDE_FILE(sys/ioctl.h HAVE_SYS_IOCTL_H)
    CHECK_INCLUDE_FILE(net/if.h HAVE_NET_IF_H)
    CHECK_INCLUDE_FILE(sys/systeminfo.h HAVE_SYS_SYSTEMINFO_H)
    CHECK_INCLUDE_FILE(sys/utsname.h HAVE_SYS_UTSNAME_H)
    CHECK_INCLUDE_FILE(sysent.h HAVE_SYSENT_H)
    CHECK_INCLUDE_FILE(unistd.h HAVE_UNISTD_H)
    CHECK_INCLUDE_FILE(sys/unistd.h HAVE_SYS_UNISTD_H)
    CHECK_INCLUDE_FILE(sys/socket.h HAVE_SYS_SOCKET_H)
    CHECK_INCLUDE_FILE(ndir.h HAVE_NDIR_H)
    CHECK_INCLUDE_FILE(sys/ndir.h HAVE_SYS_NDIR_H)
    CHECK_INCLUDE_FILE(dir.h HAVE_DIR_H)
    CHECK_INCLUDE_FILE(signal.h HAVE_SIGNAL_H)
    CHECK_INCLUDE_FILE(sys/signal.h HAVE_SYS_SIGNAL_H)
    CHECK_INCLUDE_FILE(sigfpe.h HAVE_SIGFPE_H)
    CHECK_INCLUDE_FILE(floatingpoint.h HAVE_FLOATINGPOINT_H)
    CHECK_INCLUDE_FILE(sys/machsig.h HAVE_SYS_MACHSIG_H)
    CHECK_INCLUDE_FILE(sys/siginfo.h HAVE_SYS_SIGINFO_H)
    CHECK_INCLUDE_FILE(malloc.h HAVE_MALLOC_H)
    CHECK_INCLUDE_FILE(strings.h HAVE_STRINGS_H)
    CHECK_INCLUDE_FILE(sys/stat.h HAVE_SYS_STAT_H)
    CHECK_INCLUDE_FILE(sys/sem.h HAVE_SYS_SEM_H)
    CHECK_INCLUDE_FILE(sys/ipc.h HAVE_SYS_IPC_H)
    CHECK_INCLUDE_FILE(sys/times.h HAVE_SYS_TIMES_H)
    CHECK_INCLUDE_FILE(dirent.h HAVE_DIRENT_H)
    CHECK_INCLUDE_FILE(getopt.h HAVE_GETOPT_H)
    CHECK_INCLUDE_FILE(sys/vnode.h HAVE_SYS_VNODE_H)
    INCLUDE(CheckIncludeFileCXX)
    CHECK_INCLUDE_FILE_CXX(float.h HAVE_FLOAT_H)
    CHECK_INCLUDE_FILE_CXX(iomanip.h HAVE_IOMANIP_H)
    CHECK_INCLUDE_FILE_CXX(limits.h HAVE_LIMITS_H)
    CHECK_INCLUDE_FILE_CXX(values.h HAVE_VALUES_H)
    CHECK_INCLUDE_FILE_CXX(istream HAVE_ISTREAM)
    CHECK_INCLUDE_FILE_CXX(ostream HAVE_OSTREAM)
    CHECK_INCLUDE_FILE_CXX(fstream HAVE_FSTREAM)
    CHECK_INCLUDE_FILE_CXX(ios HAVE_IOS)
    CHECK_INCLUDE_FILE_CXX(iomanip HAVE_IOMANIP)
    CHECK_INCLUDE_FILE_CXX(iostream HAVE_IOSTREAM)
    CHECK_INCLUDE_FILE_CXX(stream.h HAVE_STREAM_H)
    CHECK_INCLUDE_FILE_CXX(strstream.h HAVE_STRSTREAM_H)
    CHECK_INCLUDE_FILE_CXX(istream.h HAVE_ISTREAM_H)
    CHECK_INCLUDE_FILE_CXX(ostream.h HAVE_OSTREAM_H)
    CHECK_INCLUDE_FILE_CXX(fstream.h HAVE_FSTREAM)
    CHECK_INCLUDE_FILE_CXX(iostream.h HAVE_IOSTREAM_H)
    CHECK_INCLUDE_FILE_CXX(stdlib.h HAVE_STDLIB_H)
    CHECK_INCLUDE_FILE_CXX(siginfo.h HAVE_SIGINFO_H)
    CHECK_INCLUDE_FILE_CXX(bits/sigset.h HAVE_BITS_SIGSET_H)
    CHECK_INCLUDE_FILE_CXX(bstring.h HAVE_BSTRING_H)
    CHECK_INCLUDE_FILE_CXX(sys/types.h HAVE_SYS_TYPES_H)
    CHECK_INCLUDE_FILE_CXX(sys/select.h HAVE_SYS_SELECT_H)
    CHECK_INCLUDE_FILE_CXX(X11/extensions/transovl.h HAVE_X11_EXTENSIONS_TRANSOVL_H)
    CHECK_INCLUDE_FILE_CXX(X11/extensions/readdisplay.h HAVE_X11_EXTENSIONS_READDISPLAY_H)
    CHECK_INCLUDE_FILE_CXX(X11/extensions/multibuf.h HAVE_X11_EXTENSIONS_MULTIBUF_H)
    CHECK_INCLUDE_FILE_CXX(sys/filio.h HAVE_SYS_FILIO_H)
    CHECK_INCLUDE_FILE_CXX(sys/mman.h HAVE_SYS_MMAN_H)
    CHECK_INCLUDE_FILE_CXX(libc.h HAVE_LIBC_H)
    # Check library functions
    INCLUDE(CheckFunctionExists)
    CHECK_FUNCTION_EXISTS(alloca HAVE_ALLOCA)
    CHECK_FUNCTION_EXISTS(memcmp HAVE_MEMCMP)
    CHECK_FUNCTION_EXISTS(signal HAVE_SIGNAL)
    CHECK_FUNCTION_EXISTS(gethostname HAVE_GETHOSTNAME)
    CHECK_FUNCTION_EXISTS(putenv HAVE_PUTENV)
    CHECK_FUNCTION_EXISTS(re_comp HAVE_RE_COMP)
    CHECK_FUNCTION_EXISTS(regcomp HAVE_REGCOMP)
    CHECK_FUNCTION_EXISTS(strcspn HAVE_STRCSPN)
    CHECK_FUNCTION_EXISTS(strdup HAVE_STRDUP)
    CHECK_FUNCTION_EXISTS(strtol HAVE_STRTOL)
    CHECK_FUNCTION_EXISTS(statfs HAVE_STATFS)
    CHECK_FUNCTION_EXISTS(statvfs HAVE_STATVFS)
    CHECK_FUNCTION_EXISTS(finite HAVE_FINITE)
    CHECK_FUNCTION_EXISTS(mallinfo HAVE_MALLINFO)
    SET(CMAKE_REQUIRED_LIBRARIES sunmath)
    CHECK_FUNCTION_EXISTS(ieee_handler HAVE_SUNMATH)
    SET(CMAKE_REQUIRED_LIBRARIES)
    SET(RETSIGTYPE void) # Don't know how to figure this out yet
    INCLUDE(CheckTypeSize)
    SET(CMAKE_EXTRA_INCLUDE_FILES sys/time.h)
    CHECK_TYPE_SIZE(tm TM_IN_SYS_TIME)
    SET(CMAKE_EXTRA_INCLUDE_FILES) 
    INCLUDE (CheckCSourceCompiles)
    CHECK_C_SOURCE_COMPILES("
    #include <sys/time.h>
    #include <sys/sem.h>
    int main(){union semun c;return 0;}
    "
    SEMUN_DEFINED)
    IF (SEMUN_DEFINED)
    	CHECK_C_SOURCE_COMPILES("
    	#include <sys/time.h>
    	#include <sys/sem.h>
    	int main(){union semun c;c.__buf = 0;return 0;}
    	"
    	SEMUN_BUF_DEFINED)
    ENDIF (SEMUN_DEFINED)
    CHECK_C_SOURCE_COMPILES("
    #include <sys/sem.h>
    static struct sembuf event_flag;
    int main(){int status; int *semid;status = semop(*semid,event_flag,1);return 0;}
    "
    SEMOP_NO_REFERENCE)

    CHECK_C_SOURCE_COMPILES("
    #include <sys/sem.h>
    int get_semaphore(int *semid,int *event,int *value)
    {
        int status;
        status = semctl((*semid),*event,GETVAL,value);
        return 0;
    }
    int main(){ int *a,*b,*c;
    if(get_semaphore(a,b,c))
        return 0;
    return 0;}
    "
    SEMCTL_NO_REFERENCE)

    INCLUDE (CheckCXXSourceCompiles)
    CHECK_CXX_SOURCE_COMPILES("
    #include <ios>
    int main(){static const int input = (std::ios::in)|(std::ios::nocreate);
    static const int output = (std::ios::out);return 0;}
    "
    DEF_IOS_OK)
    CHECK_CXX_SOURCE_COMPILES("
    #include <sys/types.h>
    size_t a;
    int main(){return 0;}
    "
    SYS_TYPES_DEFINES_SIZE_T)
    IF(NOT SYS_TYPES_DEFINES_SIZE_T)
	SET(SYS_TYPES_DEFINES_SIZE_T 0)
    ENDIF(NOT SYS_TYPES_DEFINES_SIZE_T)
    CHECK_CXX_SOURCE_COMPILES("
    #include <iostream>
    int main(){std::cout << std::cout.form(\"%9.3e\", 3.14159627e-4) << std::endl;return 0;}
    "
    OSTREAM_FORM_OK)	
    INCLUDE(TestBigEndian)
    TEST_BIG_ENDIAN(WORDS_BIGENDIAN)
    SET(STDC_HEADERS TRUE) # Only for really old systems, being lazy
    SET(STACK_DIRECTION 0) # Don't have a test for this, TODO?


# TODO: check all headers/functions/libraries that are checked in configure.ac original OCC script
# TODO: generate the config.h file from these checks
ENDIF(NOT WIN32)

CONFIGURE_FILE( ${CMAKE_CURRENT_SOURCE_DIR}/occ_config.h.cmake
	${CMAKE_CURRENT_BINARY_DIR}/inc/occ_config.h )

############################
# Check 32/64 bit platform #
############################
IF (${CMAKE_SIZEOF_VOID_P} MATCHES "8") # It is 64bit, otherwise 32 bit systems match 4
    ADD_DEFINITIONS(-D_OCC64)
    SET(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} -m64)
    MESSAGE(STATUS "Build 64bit")
    SET(MODE "64bit")
    SET(BIT 64)
ELSE (${CMAKE_SIZEOF_VOID_P} MATCHES "8")
    MESSAGE(STATUS "Build 32bit")
    SET(BIT 32)
ENDIF(${CMAKE_SIZEOF_VOID_P} MATCHES "8")
# TODO: add optional 32/64 bit compilation mode to overwrite this default setting (one eventually
#       would like to compile OCC in 32bit mode even on a 64bit machine).

#######################################################
# Check platforms - Define specific compilation flags #
#######################################################
IF(UNIX)
  IF(APPLE)
    ######### MacOSX ###########
    MESSAGE(STATUS "MacOSX platform detected")
    SET(PLATFORM Darwin)
    ADD_DEFINITIONS(-DHAVE_OCC_CONFIG_H -DCSFDB -DLIN -DOCC_CONVERT_SIGNALS)
  ELSE(APPLE)
    ######### Unix/Linux ###########
    MESSAGE(STATUS "Unix/Linux platform detected")
    ADD_DEFINITIONS(-DHAVE_OCC_CONFIG_H -DCSFDB -DLIN -DOCC_CONVERT_SIGNALS)
    SET(PLATFORM Unix)
  ENDIF(APPLE)
ELSE(UNIX)
  IF(WIN32)
    ######### Windows ###########
    MESSAGE(STATUS "Windows system detected")
    ADD_DEFINITIONS(-DWNT -DWIN32 -D_WINDOWS -DCSFDB)
    SET(PLATFORM win)
  ELSE(WIN32)
    MESSAGE(STATUS "Unknown platform")
  ENDIF(WIN32)
ENDIF(UNIX)
# TODO: better detection of different Unices (Linux, Solaris etc.)
# TODO: add CXX compiler flags for each platform

################################################
# Define output path for generated libraries:  #
# platform/compiler-build_type-bits           #
# for instance:                                #
#     ./win32/bin/vc7.1-release-64             #
#     ./win32/bin/vc9-debug-32                 #
#     ./Unix/i386-debug-64                      #
################################################
IF(WIN32)
    IF(${MSVC}) # The compiler used is MSVC
        MESSAGE(STATUS "Found MSVC compiler: ${MSVC} ${MSVC_VERSION}")
        SET(LIBRARY_OUTPUT_PATH win${BIT}/${MSVC_VERSION}-${CMAKE_BUILD_TYPE}/bin)
    ELSE(${MSVC})
        SET(LIBRARY_OUTPUT_PATH win${BIT}/bin/${CMAKE_BUILD_TYPE})
    ENDIF(${MSVC})
ELSE(WIN32)
    SET(LIBRARY_OUTPUT_PATH ${PLATFORM}/${CMAKE_SYSTEM_PROCESSOR}-${CMAKE_BUILD_TYPE}-${BIT})
ENDIF(WIN32)
MESSAGE(STATUS "output_path: ${LIBRARY_OUTPUT_PATH}")
# TODO: under win32/64, dlls and libs should not be in the same path

###############################################
# Build the list of all OCC Toolkits to build #
###############################################
LIST(APPEND OCC_ToolKits ${FOUNDATION_PKGS} ${MODELLINGDATA_PKGS}
	${MODELLINGALGORITHMS_PKGS} ${VISUALISATION_PKGS} ${OCAF_PKGS}
	${DATAEXCHANGE_PKGS} ${DRAW_PKGS} ${WOK_PKGS} ${WRAPPER_PKGS})
LIST(APPEND OCC_Apps ${DRAW_APP})

###################################
# Define the list of install pkgs #
###################################
SET(OPENCASCADE_INSTALL_PKGS ${FOUNDATION_INSTALL_PKGS}
	${VISUALISATION_INSTALL_PKGS} ${OCAF_INSTALL_PKGS}
	${DATAEXCHANGE_INSTALL_PKGS} ${DRAW_INSTALL_PKGS})

####################################################################################
# Define the list of modules of each ToolKit                                       #
# The name of this list is ToolKit_MODULES: TKService_MODULES, TKBRep_MODULES etc. #
# Dependencies for each ToolKit: a list ToolKit_REQUIRED_LIBRARIES is created      #
# for each ToolKit                                                                 #
####################################################################################
# Foundation
# TKernel Toolkit
LIST(APPEND TKernel_MODULES FSD MMgt OSD Plugin Quantity Resource SortTools Standard
	StdFail Storage TColStd TCollection TShort Units UnitsAPI IncludeLibrary 
	Dico NCollection Message)
LIST(APPEND TKernel_REQUIRED_LIBRARIES)

# TKMath Toolkit
LIST(APPEND TKMath_MODULES math ElCLib ElSLib BSplCLib BSplSLib PLib Precision GeomAbs 
	Poly CSLib Convert Bnd gp TColgp TopLoc)
LIST(APPEND TKMath_REQUIRED_LIBRARIES TKernel)

# TKAdvTools Toolkit
LIST(APPEND TKAdvTools_MODULES Dynamic Materials Expr ExprIntrp GraphDS GraphTools)
LIST(APPEND TKAdvTools_REQUIRED_LIBRARIES TKernel)

# Modeling Data
# TKG2d Toolkit
LIST(APPEND TKG2d_MODULES Geom2d LProp TColGeom2d Adaptor2d Geom2dLProp Geom2dAdaptor TopAbs GProp)
LIST(APPEND TKG2d_REQUIRED_LIBRARIES ${TKMath_REQUIRED_LIBRARIES} TKMath)

# TKG3d Toolkit
LIST(APPEND TKG3d_MODULES Geom TColGeom GeomAdaptor AdvApprox GeomLProp Adaptor3d LProp3d)
LIST(APPEND TKG3d_REQUIRED_LIBRARIES ${TKG2d_REQUIRED_LIBRARIES} TKG2d)

# TKGeomBase Toolkit
LIST(APPEND TKGeomBase_MODULES ProjLib GeomProjLib GCPnts CPnts Approx AppParCurves 
	FEmTool AppCont Extrema IntAna IntAna2d GeomConvert AdvApp2Var GeomLib 
	Geom2dConvert Hermit BndLib AppDef GeomTools GC GCE2d gce)
LIST(APPEND TKGeomBase_REQUIRED_LIBRARIES ${TKG3d_REQUIRED_LIBRARIES} TKG3d)

# TKBRep Toolkit
LIST(APPEND TKBRep_MODULES TopoDS TopExp TopTools BRep BRepLProp BRepAdaptor BRepTools)
LIST(APPEND TKBRep_REQUIRED_LIBRARIES ${TKGeomBase_REQUIRED_LIBRARIES} TKGeomBase)

# Modeling Algorithms
# TKGeomAlgo Toolkit
LIST(APPEND TKGeomAlgo_MODULES Hatch GeomInt IntStart IntWalk IntImp IntCurveSurface 
	IntSurf IntPatch Geom2dInt IntImpParGen IntRes2d IntCurve TopTrans Intf ApproxInt GccAna 
	GccEnt GccInt GccIter GccGeo HatchGen Geom2dHatch Law AppBlend Plate GeomPlate 
	LocalAnalysis GeomAPI GeomFill Geom2dAPI Geom2dGcc FairCurve NLPlate IntPolyh TopClass)
LIST(APPEND TKGeomAlgo_REQUIRED_LIBRARIES ${TKBRep_REQUIRED_LIBRARIES} TKBRep)

# TKTopAlgo Toolkit
LIST(APPEND TKTopAlgo_MODULES IntCurvesFace MAT MAT2d Bisector BRepMAT2d BRepCheck 
	BRepBndLib BRepExtrema BRepClass BRepClass3d BRepLib BRepGProp BRepIntCurveSurface 
	BRepTopAdaptor BRepBuilderAPI BRepApprox)
LIST(APPEND TKTopAlgo_REQUIRED_LIBRARIES ${TKGeomAlgo_REQUIRED_LIBRARIES} TKGeomAlgo)

# TKPrim Toolkit
LIST(APPEND TKPrim_MODULES BRepPrim Primitives BRepSweep Sweep BRepPrimAPI)
LIST(APPEND TKPrim_REQUIRED_LIBRARIES ${TKTopAlgo_REQUIRED_LIBRARIES} TKTopAlgo)

# TKMesh Toolkit
LIST(APPEND TKMesh_MODULES Triangle MeshDS BRepMesh MeshShape MeshAlgo IntPoly)
LIST(APPEND TKMesh_REQUIRED_LIBRARIES ${TKTopAlgo_REQUIRED_LIBRARIES} TKTopAlgo)

# TKXMesh Toolkit
LIST(APPEND TKXMesh_MODULES XBRepMesh)
LIST(APPEND TKXMesh_REQUIRED_LIBRARIES ${TKMesh_REQUIRED_LIBRARIES} TKMesh)

# TKBO Toolkit
LIST(APPEND TKBO_MODULES BOPTColStd BOPTools BOP BooleanOperations IntTools BRepAlgoAPI)
LIST(APPEND TKBO_REQUIRED_LIBRARIES ${TKPrim_REQUIRED_LIBRARIES} TKPrim)

# TKBool Toolkit
LIST(APPEND TKBool_MODULES TopOpeBRep TopOpeBRepDS TopOpeBRepBuild TopOpeBRepTool BRepAlgo BRepFill BRepProj)
LIST(APPEND TKBool_REQUIRED_LIBRARIES ${TKBO_REQUIRED_LIBRARIES} TKBO)

# TKFillet Toolkit
LIST(APPEND TKFillet_MODULES ChFiDS ChFi2d ChFi3d ChFiKPart Blend BRepBlend BlendFunc BRepFilletAPI FilletSurf)
LIST(APPEND TKFillet_REQUIRED_LIBRARIES ${TKBool_REQUIRED_LIBRARIES} TKBool)

# TKHLR Toolkit
LIST(APPEND TKHLR_MODULES HLRTopoBRep HLRBRep HLRAlgo Intrv TopBas TopCnx Contap)
LIST(APPEND TKHLR_REQUIRED_LIBRARIES ${TKBool_REQUIRED_LIBRARIES} TKBool)

# TKFeat Toolkit
LIST(APPEND TKFeat_MODULES LocOpe BRepFeat)
LIST(APPEND TKFeat_REQUIRED_LIBRARIES ${TKBool_REQUIRED_LIBRARIES} TKBool)

# TKShHealing Toolkit
LIST(APPEND TKShHealing_MODULES ShapeBuild ShapeExtend ShapeConstruct ShapeCustom 
	ShapeAnalysis ShapeFix ShapeUpgrade ShapeAlgo ShapeProcess ShapeProcessAPI)
LIST(APPEND TKShHealing_REQUIRED_LIBRARIES ${TKBool_REQUIRED_LIBRARIES} TKBool)

# TKOffset Toolkit
LIST(APPEND TKOffset_MODULES BRepOffsetAPI Draft BRepOffset BiTgte)
LIST(APPEND TKOffset_REQUIRED_LIBRARIES ${TKBool_REQUIRED_LIBRARIES} TKBool
	TKShHealing)

# TKService Toolkit
#LIST(APPEND TKService_MODULES Aspect InterfaceGraphic SelectBasics Viewer Xw MFT PS CGM AlienImage Image PlotMgt ImageUtility WNT TColQuantity)
IF (WIN32)
	LIST(APPEND TKService_MODULES Aspect InterfaceGraphic SelectBasics Viewer MFT PS
		CGM AlienImage Image PlotMgt WNT TColQuantity)
ELSE(WIN32)
	LIST(APPEND TKService_MODULES AlienImage Aspect CGM Image ImageUtility
		MFT PS PlotMgt SelectBasics TColQuantity Viewer Xw)
ENDIF(WIN32)
LIST(APPEND TKService_REQUIRED_LIBRARIES ${TKMath_REQUIRED_LIBRARIES} TKMath)

# TKV2d Toolkit
LIST(APPEND TKV2d_MODULES V2d Graphic2d Select2D Prs2d AIS2D GGraphic2d)
LIST(APPEND TKV2d_REQUIRED_LIBRARIES ${TKService_REQUIRED_LIBRARIES} TKService TKHLR)

# TKV3d Toolkit
LIST(APPEND TKV3d_MODULES V3d Graphic3d Visual3d Select3D Prs3d StdPrs SelectMgr PrsMgr AIS DsgPrs StdSelect Voxel)
LIST(APPEND TKV3d_REQUIRED_LIBRARIES ${TKV2d_REQUIRED_LIBRARIES} ${TKHLR_REQUIRED_LIBRARIES} TKV2d TKHLR TKMesh)

# TKOpenGl Toolkit
LIST(APPEND TKOpenGl_MODULES OpenGl)
LIST(APPEND TKOpenGl_REQUIRED_LIBRARIES ${TKV3d_REQUIRED_LIBRARIES} TKV3d)

# TKMeshVS Toolkit
LIST(APPEND TKMeshVS_MODULES MeshVS)
LIST(APPEND TKMeshVS_REQUIRED_LIBRARIES ${TKV3d_REQUIRED_LIBRARIES} TKV3d)

# TKNIS Toolkit
LIST(APPEND TKNIS_MODULES NIS)
LIST(APPEND TKNIS_REQUIRED_LIBRARIES ${TKV3d_REQUIRED_LIBRARIES} TKV3d)

# Application framework
# TKCDF Toolkit
LIST(APPEND TKCDF_MODULES CDM PCDM CDF UTL LDOM)
LIST(APPEND TKCDF_REQUIRED_LIBRARIES TKernel)

# PTKernel Toolkit
LIST(APPEND PTKernel_MODULES DBC PCollection PColStd PMMgt PShort PStandard PTColStd ObjMgt)
LIST(APPEND PTKernel_REQUIRED_LIBRARIES TKernel)

# TKLCAF Toolkit
LIST(APPEND TKLCAF_MODULES TDataStd TDF TDocStd TNaming AppStdL)
LIST(APPEND TKLCAF_REQUIRED_LIBRARIES ${TKTopAlgo_REQUIRED_LIBRARIES} TKTopAlgo TKCDF)

# FWOSPlugin
LIST(APPEND FWOSPlugin_MODULES FWOSDriver)
LIST(APPEND FWOSPlugin_REQUIRED_LIBRARIES ${TKCDF_REQUIRED_LIBRARIES} TKCDF)

# TKPShape Toolkit
LIST(APPEND TKPShape_MODULES PBRep PTopoDS PGeom PGeom2d PPoly PColgp PTopLoc PColPGeom PColPGeom2d MgtBRep MgtGeom MgtGeom2d MgtPoly MgtTopLoc MgtTopoDS)
LIST(APPEND TKPShape_REQUIRED_LIBRARIES ${PTKernel_REQUIRED_LIBRARIES} ${TKBRep_REQUIRED_LIBRARIES} PTKernel TKBRep)

# TKCAF Toolkit
LIST(APPEND TKCAF_MODULES TPrsStd TFunction AppStd)
LIST(APPEND TKCAF_REQUIRED_LIBRARIES ${TKLCAF_REQUIRED_LIBRARIES} ${TKV3d_REQUIRED_LIBRARIES} TKLCAF TKV3d)

# TKBinL Toolkit
LIST(APPEND TKBinL_MODULES BinLDrivers BinMDF BinMDataStd BinMNaming BinObjMgt BinMDocStd BinTools)
LIST(APPEND TKBinL_REQUIRED_LIBRARIES ${TKLCAF_REQUIRED_LIBRARIES} ${TKV3d_REQUIRED_LIBRARIES} TKLCAF TKV3d)

# TKXmlL Toolkit
LIST(APPEND TKXmlL_MODULES XmlLDrivers XmlMDF XmlMDataStd XmlMDocStd XmlMNaming XmlObjMgt)
LIST(APPEND TKXmlL_REQUIRED_LIBRARIES ${TKLCAF_REQUIRED_LIBRARIES} TKLCAF)

# TKTObj Toolkit
LIST(APPEND TKTObj_MODULES TObj)
LIST(APPEND TKTObj_REQUIRED_LIBRARIES ${TKLCAF_REQUIRED_LIBRARIES} TKLCAF)

# TKShapeSchema Toolkit
LIST(APPEND TKShapeSchema_MODULES ShapeSchema PCDMShape)
LIST(APPEND TKShapeSchema_REQUIRED_LIBRARIES ${TKCDF_REQUIRED_LIBRARIES} ${TKPShape_REQUIRED_LIBRARIES} TKCDF TKPShape)

# TKPLCAF Toolkit
LIST(APPEND TKPLCAF_MODULES PDF PDocStd PNaming PDataStd MDF MDocStd MDataStd MNaming)
LIST(APPEND TKPLCAF_REQUIRED_LIBRARIES ${TKPShape_REQUIRED_LIBRARIES} ${TKLCAF_REQUIRED_LIBRARIES} TKPShape TKLCAF)

# TKBin Toolkit
LIST(APPEND TKBin_MODULES BinDrivers BinMFunction BinMPrsStd)
LIST(APPEND TKBin_REQUIRED_LIBRARIES ${TKBinL_REQUIRED_LIBRARIES} TKBinL TKCDF TKCAF)

# TKXml Toolkit
LIST(APPEND TKXml_MODULES XmlDrivers XmlMFunction XmlMPrsStd)
LIST(APPEND TKXml_REQUIRED_LIBRARIES ${TKCAF_REQUIRED_LIBRARIES} ${TKXmlL_REQUIRED_LIBRARIES} TKCAF TKXmlL)

# TKBinTObj Toolkit
LIST(APPEND TKBinTObj_MODULES BinTObjDrivers)
LIST(APPEND TKBinTObj_REQUIRED_LIBRARIES ${TKBinL_REQUIRED_LIBRARIES} TKBinL TKCDF TKTObj)

# TKXmlTObj Toolkit
LIST(APPEND TKXmlTObj_MODULES XmlTObjDrivers)
LIST(APPEND TKXmlTObj_REQUIRED_LIBRARIES ${TKXmlL_REQUIRED_LIBRARIES} TKXmlL TKCDF TKTObj)

# TKPCAF Toolkit
LIST(APPEND TKPCAF_MODULES PPrsStd MPrsStd PFunction MFunction)
LIST(APPEND TKPCAF_REQUIRED_LIBRARIES ${TKPShape_REQUIRED_LIBRARIES} ${TKCAF_REQUIRED_LIBRARIES} ${TKPLCAF_REQUIRED_LIBRARIES} TKPShape TKCAF TKPLCAF)

# TKStdLSchema Toolkit
LIST(APPEND TKStdLSchema_MODULES StdLSchema StdLDrivers)
LIST(APPEND TKStdLSchema_REQUIRED_LIBRARIES ${TKPLCAF_REQUIRED_LIBRARIES} TKPLCAF TKShapeSchema)

# TKStdSchema Toolkit
LIST(APPEND TKStdSchema_MODULES StdSchema StdDrivers)
LIST(APPEND TKStdSchema_REQUIRED_LIBRARIES ${TKPCAF_REQUIRED_LIBRARIES} TKPCAF TKStdLSchema)

# StdPlugin
LIST(APPEND StdPlugin_MODULES StdPlugin)
LIST(APPEND StdPlugin_REQUIRED_LIBRARIES ${TKPLCAF_REQUIRED_LIBRARIES} ${TKLCAF_REQUIRED_LIBRARIES} ${TKStdLSchema_REQUIRED_LIBRARIES} TKPLCAF TKLCAF TKStdLSchema TKStdSchema)

# XmlPlugin
LIST(APPEND XmlPlugin_MODULES XmlPlugin)
LIST(APPEND XmlPlugin_REQUIRED_LIBRARIES TKXml TKXmlL TKLCAF TKCDF TKCAF TKV3d
	TKernel TKMesh TKGeomAlgo TKV2d TKTopAlgo TKHLR TKGeomBase TKService TKG2d
	TKBRep TKMath TKG3d)

# BinPlugin
LIST(APPEND BinPlugin_MODULES BinPlugin)
LIST(APPEND BinPlugin_REQUIRED_LIBRARIES TKBin TKCAF TKV3d TKernel TKMesh TKGeomAlgo
	TKV2d TKTopAlgo TKHLR TKGeomBase TKService TKBinL TKLCAF TKCDF TKG2d TKBRep
	TKMath TKG3d)

# StdLPlugin
LIST(APPEND StdLPlugin_MODULES StdLPlugin)
LIST(APPEND StdLPlugin_REQUIRED_LIBRARIES ${TKPLCAF_REQUIRED_LIBRARIES} ${TKLCAF_REQUIRED_LIBRARIES} ${TKStdLSchema_REQUIRED_LIBRARIES} TKPLCAF TKLCAF TKStdLSchema)

# BinLPlugin
LIST(APPEND BinLPlugin_MODULES BinLPlugin)
LIST(APPEND BinLPlugin_REQUIRED_LIBRARIES TKBinL TKLCAF TKCDF TKGeomBase
	TKGeomAlgo TKTopAlgo TKG2d TKBRep TKMath TKernel TKG3d)

# XmlLPlugin
LIST(APPEND XmlLPlugin_MODULES XmlLPlugin)
LIST(APPEND XmlLPlugin_REQUIRED_LIBRARIES TKXmlL TKLCAF TKCDF TKGeomBase
	TKGeomAlgo TKTopAlgo TKG2d TKBRep TKMath TKernel TKG3d)

# BinTObjPlugin
LIST(APPEND BinTObjPlugin_MODULES BinTObjPlugin)
LIST(APPEND BinTObjPlugin_REQUIRED_LIBRARIES TKBinTObj TKTObj TKBinL TKLCAF
	TKCDF TKGeomBase TKGeomAlgo TKTopAlgo TKG2d TKBRep TKMath TKernel TKG3d)

# XmlTObjPlugin
LIST(APPEND XmlTObjPlugin_MODULES XmlTObjPlugin)
LIST(APPEND XmlTObjPlugin_REQUIRED_LIBRARIES TKXmlTObj TKXmlL TKTObj TKLCAF
	TKCDF TKGeomBase TKGeomAlgo TKTopAlgo TKG2d TKBRep TKMath TKernel TKG3d)

# Data exchange
# TKVRML Toolkit
LIST(APPEND TKVRML_MODULES VrmlConverter VrmlAPI Vrml VrmlData)
LIST(APPEND TKVRML_REQUIRED_LIBRARIES ${TKV3d_REQUIRED_LIBRARIES} TKV3d TKMesh)

# TKXCAF Toolkit
LIST(APPEND TKXCAF_MODULES XCAFApp XCAFDoc XCAFPrs)
LIST(APPEND TKXCAF_REQUIRED_LIBRARIES ${TKCAF_REQUIRED_LIBRARIES} TKCAF)

# TKSTL Toolkit
LIST(APPEND TKSTL_MODULES StlMesh StlAPI StlTransfer RWStl)
LIST(APPEND TKSTL_REQUIRED_LIBRARIES ${TKOffset_REQUIRED_LIBRARIES} TKOffset TKMesh)

# TKXSBase Toolkit
LIST(APPEND TKXSBase_MODULES Interface Transfer IFGraph IFSelect TransferBRep XSControl StepData StepFile HeaderSection RWHeaderSection APIHeaderSection StepSelect UnitsMethods XSAlgo LibCtl MoniTool)
LIST(APPEND TKXSBase_REQUIRED_LIBRARIES ${TKShHealing_REQUIRED_LIBRARIES} TKShHealing)

# TKXCAFSchema Toolkit
LIST(APPEND TKXCAFSchema_MODULES MXCAFDoc PXCAFDoc XCAFDrivers XCAFSchema)
LIST(APPEND TKXCAFSchema_REQUIRED_LIBRARIES ${TKPCAF_REQUIRED_LIBRARIES} ${TKXCAF_REQUIRED_LIBRARIES} ${TKStdLSchema_REQUIRED_LIBRARIES} ${TKStdSchema_REQUIRED_LIBRARIES} TKPCAF TKXCAF TKStdLSchema TKStdSchema TKShapeSchema)

# TKXmlXCAF Toolkit
LIST(APPEND TKXmlXCAF_MODULES XmlXCAFDrivers XmlMXCAFDoc)
LIST(APPEND TKXmlXCAF_REQUIRED_LIBRARIES ${TKXCAF_REQUIRED_LIBRARIES} ${TKXml_REQUIRED_LIBRARIES} TKXCAF TKXml)

# TKBinXCAF Toolkit
LIST(APPEND TKBinXCAF_MODULES BinXCAFDrivers BinMXCAFDoc)
LIST(APPEND TKBinXCAF_REQUIRED_LIBRARIES ${TKBin_REQUIRED_LIBRARIES} TKBin TKXCAF)

# TKSTEPBase Toolkit
LIST(APPEND TKSTEPBase_MODULES StepBasic RWStepBasic StepRepr RWStepRepr StepGeom RWStepGeom StepShape RWStepShape)
LIST(APPEND TKSTEPBase_REQUIRED_LIBRARIES ${TKXSBase_REQUIRED_LIBRARIES} ${TKMath_REQUIRED_LIBRARIES} TKXSBase TKMath)

# TKIGES Toolkit
LIST(APPEND TKIGES_MODULES IGESData IGESFile IGESBasic IGESGraph IGESGeom IGESDimen IGESDraw IGESSolid IGESDefs IGESAppli IGESConvGeom IGESSelect IGESToBRep GeomToIGES Geom2dToIGES BRepToIGES BRepToIGESBRep IGESControl)
LIST(APPEND TKIGES_REQUIRED_LIBRARIES ${TKOffset_REQUIRED_LIBRARIES} ${TKXSBase_REQUIRED_LIBRARIES} TKOffset TKXSBase)

# TKSTEPAttr Toolkit
LIST(APPEND TKSTEPAttr_MODULES StepVisual RWStepVisual StepDimTol RWStepDimTol)
LIST(APPEND TKSTEPAttr_REQUIRED_LIBRARIES ${TKSTEPBase_REQUIRED_LIBRARIES} TKSTEPBase)

# TKSTEP209 Toolkit
LIST(APPEND TKSTEP209_MODULES StepElement StepFEA RWStepElement RWStepFEA)
LIST(APPEND TKSTEP209_REQUIRED_LIBRARIES ${TKSTEPBase_REQUIRED_LIBRARIES} TKSTEPBase)

# TKXDEIGES Toolkit
LIST(APPEND TKXDEIGES_MODULES IGESCAFControl)
LIST(APPEND TKXDEIGES_REQUIRED_LIBRARIES ${TKXCAF_REQUIRED_LIBRARIES} ${TKIGES_REQUIRED_LIBRARIES} TKXCAF TKIGES)

# TKSTEP Toolkit
LIST(APPEND TKSTEP_MODULES StepAP214 RWStepAP214 StepAP203 RWStepAP203 STEPConstruct STEPEdit GeomToStep StepToGeom StepToTopoDS TopoDSToStep STEPControl STEPSelections StepAP209)
LIST(APPEND TKSTEP_REQUIRED_LIBRARIES ${TKSTEPBase_REQUIRED_LIBRARIES}
	TKSTEPBase TKSTEPAttr TKSTEP209)

# TKXDESTEP Toolkit
LIST(APPEND TKXDESTEP_MODULES STEPCAFControl)
LIST(APPEND TKXDESTEP_REQUIRED_LIBRARIES ${TKXCAF_REQUIRED_LIBRARIES} ${TKSTEP_REQUIRED_LIBRARIES} TKXCAF TKSTEP)

# XCAFPlugin
LIST(APPEND XCAFPlugin_MODULES XCAFPlugin)
LIST(APPEND XCAFPlugin_REQUIRED_LIBRARIES ${TKXCAF_REQUIRED_LIBRARIES} ${TKXCAFSchema_REQUIRED_LIBRARIES} TKXCAF TKXCAFSchema)

# XmlXCAFPlugin
LIST(APPEND XmlXCAFPlugin_MODULES XmlXCAFPlugin)
LIST(APPEND XmlXCAFPlugin_REQUIRED_LIBRARIES TKXmlXCAF TKXCAF TKXml TKXmlL
	TKLCAF TKCDF TKCAF TKV3d TKernel TKMesh TKGeomAlgo TKV2d TKTopAlgo TKHLR
	TKGeomBase TKService TKG2d TKBRep TKMath TKG3d)

# BinXCAFPlugin
LIST(APPEND BinXCAFPlugin_MODULES BinXCAFPlugin)
LIST(APPEND BinXCAFPlugin_REQUIRED_LIBRARIES TKBinXCAF TKBin TKCAF TKV3d
	TKernel TKMesh TKGeomAlgo TKV2d TKTopAlgo TKHLR TKGeomBase TKService TKXCAF
	TKBinL TKLCAF TKCDF TKG2d TKBRep TKMath TKG3d)

# Draw
# TKDraw Toolkit
LIST(APPEND TKDraw_MODULES Draw DBRep DrawTrSurf)
LIST(APPEND TKDraw_REQUIRED_LIBRARIES ${TKBO_REQUIRED_LIBRARIES} ${TKHLR_REQUIRED_LIBRARIES} ${TKFillet_REQUIRED_LIBRARIES} ${TKFeat_REQUIRED_LIBRARIES} ${TKOffset_REQUIRED_LIBRARIES} TKBO TKHLR TKFillet TKFeat TKOffset TKMesh)

# TKTopTest Toolkit
LIST(APPEND TKTopTest_MODULES TestTopOpeDraw TestTopOpeTools TestTopOpe BRepTest GeometryTest HLRTest MeshTest GeomliteTest DrawFairCurve BOPTest)
LIST(APPEND TKTopTest_REQUIRED_LIBRARIES TKernel TKBool TKGeomAlgo TKMesh TKG3d TKGeomBase TKFeat TKTopAlgo TKBO TKMath
	TKG2d TKOffset TKService TKV3d TKHLR TKBRep TKFillet TKDraw TKPrim TKV2d)

# TKViewerTest Toolkit
LIST(APPEND TKViewerTest_MODULES Viewer2dTest ViewerTest)
LIST(APPEND TKViewerTest_REQUIRED_LIBRARIES ${TKV2d_REQUIRED_LIBRARIES} ${TKV3d_REQUIRED_LIBRARIES} ${TKDraw_REQUIRED_LIBRARIES} ${TKOpenGl_REQUIRED_LIBRARIES} TKV2d TKV3d TKDraw TKOpenGl)

# TKXSDRAW Toolkit
LIST(APPEND TKXSDRAW_MODULES SWDRAW XSDRAW XSDRAWIGES XSDRAWSTEP XSDRAWSTLVRML)
LIST(APPEND TKXSDRAW_REQUIRED_LIBRARIES ${TKDraw_REQUIRED_LIBRARIES} 
	${TKSTEP_REQUIRED_LIBRARIES} ${TKIGES_REQUIRED_LIBRARIES}
	${TKSTL_REQUIRED_LIBRARIES} ${TKVRML_REQUIRED_LIBRARIES}
	TKDraw TKSTEP TKIGES TKSTL TKVRML TKMeshVS)

# TKDCAF Toolkit
LIST(APPEND TKDCAF_MODULES DDF DDocStd DNaming DDataStd DPrsStd DrawDim)
LIST(APPEND TKDCAF_REQUIRED_LIBRARIES ${TKCAF_REQUIRED_LIBRARIES} ${TKViewerTest_REQUIRED_LIBRARIES} TKCAF TKViewerTest)

# TKXDEDRAW Toolkit
LIST(APPEND TKXDEDRAW_MODULES XDEDRAW)
LIST(APPEND TKXDEDRAW_REQUIRED_LIBRARIES ${TKXSDRAW_REQUIRED_LIBRARIES} ${TKXDEIGES_REQUIRED_LIBRARIES} ${TKXDESTEP_REQUIRED_LIBRARIES} ${TKDCAF_REQUIRED_LIBRARIES} ${TKViewerTest_REQUIRED_LIBRARIES} TKXSDRAW TKXDEIGES TKXDESTEP TKDCAF TKViewerTest)

# TKTObjDRAW Toolkit
LIST(APPEND TKTObjDRAW_MODULES TObjDRAW)
LIST(APPEND TKTObjDRAW_REQUIRED_LIBRARIES ${TKDCAF_REQUIRED_LIBRARIES} TKDCAF)

# DRAWEXE application
LIST(APPEND DRAWEXE_MODULES DRAWEXE)
LIST(APPEND DRAWEXE_REQUIRED_LIBRARIES TKDraw TKMesh TKGeomAlgo TKTopAlgo 
	TKHLR TKGeomBase TKG2d TKBRep TKMath TKG3d TKernel ${OPENGL_LIBRARIES}
	${TCL_LIBRARY} ${TK_LIBRARY} ${THREAD_LIBRARY})

# WOK
# TKWOK Toolkit
LIST(APPEND TKWOK_MODULES EDL MS WOKAPI WOKBuilder WOKDFLT WOKDeliv WOKMake WOKOBJS WOKOrbix WOKStep WOKTools WOKUnix WOKUtils WOKernel WOKNT)
LIST(APPEND TKWOK_REQUIRED_LIBRARIES ${TKernel_REQUIRED_LIBRARIES} TKernel)

# TKWOKTcl Toolkit
LIST(APPEND TKWOKTcl_MODULES WOKTclUtils WOKTclTools MSAPI WOKTCL)
LIST(APPEND TKWOKTcl_REQUIRED_LIBRARIES ${TKWOK_REQUIRED_LIBRARIES} TKWOK)

# TKCDLFront Toolkit
LIST(APPEND TKCDLFront_MODULES CDLFront)
LIST(APPEND TKCDLFront_REQUIRED_LIBRARIES ${TKWOK_REQUIRED_LIBRARIES} TKWOK)

# TKCPPClient Toolkit
LIST(APPEND TKCPPClient_MODULES CPPClient)
LIST(APPEND TKCPPClient_REQUIRED_LIBRARIES ${TKWOK_REQUIRED_LIBRARIES} TKWOK)

# TKCPPExt Toolkit
LIST(APPEND TKCPPExt_MODULES CPPExt)
LIST(APPEND TKCPPExt_REQUIRED_LIBRARIES ${TKWOK_REQUIRED_LIBRARIES} TKWOK)

# TKCPPIntExt Toolkit
LIST(APPEND TKCPPIntExt_MODULES CPPIntExt)
LIST(APPEND TKCPPIntExt_REQUIRED_LIBRARIES ${TKWOK_REQUIRED_LIBRARIES} TKWOK)

# TKCPPJini Toolkit
LIST(APPEND TKCPPJini_MODULES CPPJini)
LIST(APPEND TKCPPJini_REQUIRED_LIBRARIES ${TKWOK_REQUIRED_LIBRARIES} TKWOK)

# TKCSFDBSchema Toolkit
LIST(APPEND TKCSFDBSchema_MODULES CSFDBSchema)
LIST(APPEND TKCSFDBSchema_REQUIRED_LIBRARIES ${TKWOK_REQUIRED_LIBRARIES} TKWOK)

# TKIDLFront Toolkit
LIST(APPEND TKIDLFront_MODULES IDLFront)
LIST(APPEND TKIDLFront_REQUIRED_LIBRARIES ${TKWOK_REQUIRED_LIBRARIES} TKWOK)

# TKTCPPExt Toolkit
LIST(APPEND TKTCPPExt_MODULES TCPPExt)
LIST(APPEND TKTCPPExt_REQUIRED_LIBRARIES ${TKWOK_REQUIRED_LIBRARIES} TKWOK)

# WOKSH
LIST(APPEND WOKSH_MODULES WOKSH)
LIST(APPEND WOKSH_REQUIRED_LIBRARIES ${TKernel_REQUIRED_LIBRARIES} ${TKWOK_REQUIRED_LIBRARIES} ${TKWOKTcl_REQUIRED_LIBRARIES} TKernel TKWOK TKWOKTcl)

# WOKLibs
LIST(APPEND WOKLibs_MODULES WOKLibs)
LIST(APPEND WOKLibs_REQUIRED_LIBRARIES ${TKernel_REQUIRED_LIBRARIES} ${TKWOK_REQUIRED_LIBRARIES} ${TKWOKTcl_REQUIRED_LIBRARIES} TKernel TKWOK TKWOKTcl)

# Wrapper
# TKjcas wrapper
LIST(APPEND TKjcas_MODULES jcas)
LIST(APPEND TKjcas_REQUIRED_LIBRARIES ${TKernel_REQUIRED_LIBRARIES} TKernel)

IF (WIN32)
    SET(WIN32_LIBS advapi32 gdi32 user32 kernel32 opengl32 glu32 ws2_32 vfw32 odbc32 odbccp32)
ENDIF(WIN32)
MESSAGE(STATUS "${GLUT_Xmu_LIBRARY}")

##################################################################################################
# Defining libraries: the algorithm is                                                           #
#       1. A loop is performed over ToolKit lists. A library is created for each.                #
#       2. Within each ToolKit, a loop is performed over modules to find source files to compile #
##################################################################################################
SET(POSSIBLE_INSTALL_HEADERS)
FOREACH(OCC_ToolKit ${OCC_ToolKits})
	SET(CURRENT_TOOLKIT ${OCC_ToolKit})
	SET(CURRENT_TOOLKIT_MODULES ${CURRENT_TOOLKIT}_MODULES)
	MESSAGE(STATUS "Processing ToolKit: ${CURRENT_TOOLKIT}(${${CURRENT_TOOLKIT_MODULES}})")
	# init CURRENT_TOOLKIT_SOURCE_FILES variable to 0
	SET(CURRENT_TOOLKIT_SOURCE_FILES)
	SET(CURRENT_TOOLKIT_HEADER_FILES)
	SET(TARGET_INCLUDE_DIRECTORIES)
	FOREACH(MODULE ${${CURRENT_TOOLKIT_MODULES}})
		#MESSAGE(STATUS "			${MODULE}")
		# add all .cxx/*.c files or each module
		FILE(GLOB ${MODULE}_source_files src/${MODULE}/*.cxx
						 src/${MODULE}/*.c
						 drv/${MODULE}/*.cxx
						 drv/${MODULE}/*.c)
		FILE(GLOB ${MODULE}_header_files inc/Handle_${MODULE}*.hxx
			inc/${MODULE}*.hxx
			inc/Handle_${MODULE}*.h
			inc/${MODULE}*.h
			src/${MODULE}/*.hxx
			src/${MODULE}/*.lxx
			src/${MODULE}/*.gxx
			src/${MODULE}/*.h
			drv/${MODULE}/*.hxx
			drv/${MODULE}/*.ixx
			drv/${MODULE}/*.jxx
			drv/${MODULE}/*.h)
		#MESSAGE(STATUS "${${MODULE}_source_files}")
		# Build a list of all header files, with the ultimate aim of
		# forming the public or install headers
		LIST(REMOVE_DUPLICATES ${MODULE}_header_files)
		FOREACH(module_header_file ${${MODULE}_header_files})
			STRING(REGEX MATCH
				"/([a-zA-Z0-9_\\.]+.[hlgij][x]*)$" DUMMY_OUTPUT ${module_header_file} )
			LIST(APPEND POSSIBLE_INSTALL_HEADERS ${CMAKE_MATCH_1})
		ENDFOREACH(module_header_file ${${MODULE}_header_files})

		FOREACH(module_source_file ${${MODULE}_source_files})
			STRING(REGEX MATCH "${MODULE}/([a-zA-Z0-9_\\.]+.c[x]*)$" DUMMY_OUTPUT ${module_source_file} )
			STRING(REGEX REPLACE "([a-zA-Z0-9_\\.]+)c([x]*)$"
				"\\1h\\2" POSSIBLE_INSTALL_HEADER ${CMAKE_MATCH_1})
			LIST(APPEND POSSIBLE_INSTALL_HEADERS
				${POSSIBLE_INSTALL_HEADER})
			IF (WIN32)
				# For compilers under Windows a define must be set per file to correctly set the export macro
				SET_SOURCE_FILES_PROPERTIES(${module_source_file} PROPERTIES COMPILE_FLAGS "-D__${MODULE}_DLL")
			ENDIF(WIN32)
		ENDFOREACH(module_source_file ${${MODULE}_source_files})

		# append these source files to the list of source files of the toolkit
		SET(CURRENT_TOOLKIT_SOURCE_FILES ${CURRENT_TOOLKIT_SOURCE_FILES} ${${MODULE}_source_files}) 
		SET(CURRENT_TOOLKIT_HEADER_FILES ${CURRENT_TOOLKIT_HEADER_FILES} ${${MODULE}_header_files}) 
		# required include paths
		SET(TARGET_INCLUDE_DIRECTORIES 
			"${TARGET_INCLUDE_DIRECTORIES} -I${CMAKE_CURRENT_SOURCE_DIR}/src/${MODULE} -I${CMAKE_CURRENT_SOURCE_DIR}/drv/${MODULE} ")
	ENDFOREACH(MODULE ${CURRENT_TOOLKIT_MODULES})
	ADD_LIBRARY(${CURRENT_TOOLKIT} ${OPENCASCADE_LIBRARY_TYPE} ${CURRENT_TOOLKIT_SOURCE_FILES})
	# TODO Add current toolkit header files into a source group?
	# Add target specific locations of *.lxx and *.ixx files
	SET_TARGET_PROPERTIES(${CURRENT_TOOLKIT} PROPERTIES COMPILE_FLAGS "${TARGET_INCLUDE_DIRECTORIES}")
	SET_TARGET_PROPERTIES(${CURRENT_TOOLKIT} PROPERTIES VERSION
		${OpenCASCADE_VERSION_MAJOR}.${OpenCASCADE_VERSION_MINOR}.${OpenCASCADE_VERSION_PATCH}
		SOVERSION ${OpenCASCADE_VERSION_MAJOR})
	# Set dependencies for thit ToolKit
	IF ( NOT "${CURRENT_TOOLKIT}" STREQUAL "TKernel" )
		LIST(REMOVE_DUPLICATES ${CURRENT_TOOLKIT}_REQUIRED_LIBRARIES)
	ENDIF ( NOT "${CURRENT_TOOLKIT}" STREQUAL "TKernel" )
	TARGET_LINK_LIBRARIES(${CURRENT_TOOLKIT} ${${CURRENT_TOOLKIT}_REQUIRED_LIBRARIES} ${WIN32_LIBS})
ENDFOREACH(OCC_ToolKit ${OCC_ToolKits})

FOREACH(OCC_App ${OCC_Apps})
	SET(CURRENT_APP ${OCC_App})
	SET(CURRENT_APP_MODULES ${CURRENT_APP}_MODULES)
	MESSAGE(STATUS "Processing Application: ${CURRENT_APP}(${${CURRENT_APP_MODULES}})")
	# init CURRENT_APP_SOURCE_FILES variable to empty
	SET(CURRENT_APP_SOURCE_FILES)
	SET(CURRENT_APP_HEADER_FILES)
	SET(TARGET_INCLUDE_DIRECTORIES)
	FOREACH(MODULE ${${CURRENT_APP_MODULES}})
		#MESSAGE(STATUS "			${MODULE}")
		# add all .cxx/*.c files or each module
		FILE(GLOB ${MODULE}_source_files src/${MODULE}/*.cxx
						 src/${MODULE}/*.c
						 drv/${MODULE}/*.cxx
						 drv/${MODULE}/*.c)
		FILE(GLOB ${MODULE}_header_files src/${MODULE}/*.hxx
			drv/${MODULE}/*.hxx)
		#MESSAGE(STATUS "${${MODULE}_source_files}")
		# append these source files to the list of source files of the toolkit
		SET(CURRENT_APP_SOURCE_FILES ${CURRENT_APP_SOURCE_FILES} ${${MODULE}_source_files}) 
		SET(CURRENT_APP_HEADER_FILES ${CURRENT_APP_HEADER_FILES} ${${MODULE}_header_files}) 
		# required include paths
		SET(TARGET_INCLUDE_DIRECTORIES 
			"${TARGET_INCLUDE_DIRECTORIES} -I${CMAKE_CURRENT_SOURCE_DIR}/src/${MODULE} -I${CMAKE_CURRENT_SOURCE_DIR}/drv/${MODULE} ")
	ENDFOREACH(MODULE ${${CURRENT_APP_MODULES}})
	ADD_EXECUTABLE(${CURRENT_APP} ${CURRENT_APP_SOURCE_FILES})
	# Add target specific locations of *.lxx and *.ixx files
	SET_TARGET_PROPERTIES(${CURRENT_APP} PROPERTIES COMPILE_FLAGS "${TARGET_INCLUDE_DIRECTORIES}")
	LIST(REMOVE_DUPLICATES ${CURRENT_APP}_REQUIRED_LIBRARIES)
	TARGET_LINK_LIBRARIES(${CURRENT_APP} ${${CURRENT_APP}_REQUIRED_LIBRARIES} ${WIN32_LIBS})
ENDFOREACH(OCC_App ${OCC_Apps})

IF(MINGW)
	SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mthreads")
	SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mthreads")
	SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -mthreads -Wl,--export-all-symbols")
	SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -mthreads -Wl,--export-all-symbols")
	# For the file Message_MsgFile.cxx of TKernel we must additionally set the __TCollection_DLL define to resolve the needed HashCode() method
	SET_SOURCE_FILES_PROPERTIES("src/Message/Message_MsgFile.cxx" PROPERTIES COMPILE_FLAGS "-D__Message_DLL -D__TCollection_DLL")
ENDIF(MINGW)

IF(OPENCASCADE_DRAW)
	SET(DRAW_INCLUDE_DIRECTORIES "-I${TCL_INCLUDE_PATH} -I${TK_INCLUDE_PATH}")
	# INCLUDE_DIRECTORIES(${TCL_INCLUDE_PATH} ${TK_INCLUDE_PATH})
	GET_TARGET_PROPERTY(TKDraw_CFLAGS TKDraw COMPILE_FLAGS)
	SET_TARGET_PROPERTIES(TKDraw PROPERTIES COMPILE_FLAGS "${TKDraw_CFLAGS} ${DRAW_INCLUDE_DIRECTORIES} -DHAVE_IOS")
	TARGET_LINK_LIBRARIES(TKDraw ${TCL_LIBRARY} ${TK_LIBRARY})
ENDIF(OPENCASCADE_DRAW)

###########
# INSTALL #
###########
LIST(REMOVE_DUPLICATES POSSIBLE_INSTALL_HEADERS)
FOREACH(POSSIBLE_INSTALL_HEADER ${POSSIBLE_INSTALL_HEADERS})
	# Test for existence in inc/
	IF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/inc/${POSSIBLE_INSTALL_HEADER})
		LIST(APPEND INSTALL_HEADERS inc/${POSSIBLE_INSTALL_HEADER})
	ENDIF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/inc/${POSSIBLE_INSTALL_HEADER})
ENDFOREACH(POSSIBLE_INSTALL_HEADER ${POSSIBLE_INSTALL_HEADERS})
LIST(APPEND INSTALL_HEADERS ${CMAKE_CURRENT_BINARY_DIR}/inc/occ_config.h)
 
# Libraries are installed by default in /usr/local/lib/OpenCASCADE on UNIX
# based platforms and c:/OpenCASCADE-6.3.0/lib/OpenCASCADE on windows based
# platforms
SET(DEST_DIR OpenCASCADE)
INSTALL(TARGETS ${OCC_ToolKits} ${OPENCASCADE_INSTALL_TYPE}
	DESTINATION lib/${DEST_DIR})
INSTALL(TARGETS ${OCC_Apps} RUNTIME DESTINATION bin)
INSTALL(FILES ${INSTALL_HEADERS} DESTINATION include/${DEST_DIR})
FOREACH(INSTALL_PKG ${OPENCASCADE_INSTALL_PKGS})
	INSTALL(FILES ${${INSTALL_PKG}_INSTALL_FILES} 
		DESTINATION share/${DEST_DIR}/${INSTALL_PKG})
ENDFOREACH(INSTALL_PKG ${OPENCASCADE_INSTALL_PKGS})
INSTALL(FILES env.bat env.csh env.ksh env_DRAW.sh
	DESTINATION share/${DEST_DIR})

